package com.hmall.item.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ItemQueueConfig {
    /**
     * 定义交换机
     * @return
     */
    @Bean
    public DirectExchange exchange(){
        return ExchangeBuilder.directExchange("item.direct").build();
    }

    /**
     * 定义队列
     * @return
     */
    @Bean
    public Queue insert(){
        return QueueBuilder.durable("item.insert.queue").build();
    }

    /**
     * 定义队列
     * @return
     */
    @Bean
    public Queue delete(){
        return QueueBuilder.durable("item.delete.queue").build();
    }
    /**
     * 路由绑定添加队列
     */
    @Bean
    public Binding bindingInsert(){
      return   BindingBuilder.bind(insert()).to(exchange()).with("item.insert");
    }
    /**
     * 路由绑定删除队列
     */
    @Bean
    public Binding bindingDelete(){
        return BindingBuilder.bind(delete()).to(exchange()).with("item.delete");
    }
}
